package com.atguigu.spzx.manage.controller;

import com.atguigu.spzx.manage.service.EventRegisterService;
import com.atguigu.spzx.model.dto.system.EventRegisterDto;
import com.atguigu.spzx.model.entity.system.EventRegister;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

//报名管理
@RestController
@RequestMapping(value = "/admin/system/register")
@Slf4j
@Tag(name = "报名管理接口")
public class EventRegisterController {

    @Autowired
    private EventRegisterService eventRegisterService;
    //报名分页查询


    @Operation(summary = "报名管理分页查询")
    @GetMapping(value = "/findByPage/{pageNum}/{pageSize}")
    public Result<PageInfo<EventRegister>> findByPage(EventRegisterDto eventRegisterDto,
                                                      @PathVariable(value = "pageNum") Integer pageNum,
                                                      @PathVariable(value = "pageSize") Integer pageSize) {
        log.info("用户查询内容:{},页码:{},页数:{}",eventRegisterDto,pageNum,pageSize);
        PageInfo<EventRegister> pageInfo = eventRegisterService.findByPage(eventRegisterDto, pageNum, pageSize);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }
        // 添加报名
        @Operation(summary = "添加报名")
        @PostMapping(value = "/saveRegister")
        public Result saveSysUser(@RequestBody EventRegister eventRegister) {
            log.info("添加的报名:{}",eventRegister);
            eventRegisterService.saveRegister(eventRegister) ;
            return Result.build(null , ResultCodeEnum.SUCCESS) ;
        }


        @Operation(summary = "更新报名")
        @PutMapping(value = "/updateRegister")
        public Result updateSysUser(@RequestBody EventRegister eventRegister) {
            log.info("修改的报名:{}",eventRegister);
            eventRegisterService.updateRegister(eventRegister) ;
            return Result.build(null , ResultCodeEnum.SUCCESS) ;
        }

    @Operation(summary = "通过报名")
    @PutMapping(value = "/passById/{registerId}")
    public Result passById(@PathVariable(value = "registerId") Long id) {
        eventRegisterService.passById(id) ;
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }

    @Operation(summary = "驳回活动")
    @PutMapping(value = "/rejectById/{registerId}")
    public Result rejectById(@PathVariable(value = "registerId") Long id) {
        log.info("id为{}:",id);
        eventRegisterService.rejectById(id) ;
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }


    // 删除报名
        @Operation(summary = "删除报名")
        @DeleteMapping(value = "/deleteById/{registerId}")
        public Result deleteById(@PathVariable(value = "registerId") Long id) {
            log.info("id为:{}",id);
            eventRegisterService.deleteById(id) ;
            return Result.build(null , ResultCodeEnum.SUCCESS) ;
        }


//        //审批报名(审批报名成功1和报名失败2)
//        @Operation(summary = "更新报名")
//        @PutMapping(value = "/startOrStop{status}")
//        public Result AuditRegister(@PathVariable Long id,Integer status) {
//            eventRegisterService.auditRegister(id,status);
//            return Result.build("",ResultCodeEnum.SUCCESS);
//        }


}
